package com.example.bilibili.home;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.bilibili.Constants;
import com.example.bilibili.R;
import com.example.bilibili.ResultBeanData;

import java.util.List;

public class RemenGridViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<ResultBeanData.ResultBean.HotInfoBean> datas;

    public RemenGridViewAdapter(Context mContext, List<ResultBeanData.ResultBean.HotInfoBean> hot_info) {
        this.mContext = mContext;
        this.datas = hot_info;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = View.inflate(mContext, R.layout.item_remen_grid_view,null);
            viewHolder = new ViewHolder();

            viewHolder.iv_hot = (ImageView) convertView.findViewById(R.id.iv_hot);
            viewHolder.bofangliang = (TextView) convertView.findViewById(R.id.bofangliang);
            viewHolder.Id = (TextView) convertView.findViewById(R.id.Id);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_red = (TextView) convertView.findViewById(R.id.tv_red);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //根据播放量得到对应的数据
        ResultBeanData.ResultBean.HotInfoBean hotInfoBean1 = datas.get(position);
        String SHotposition=hotInfoBean1.getHotposition();
        try {
            int Hotposition = Integer.parseInt(SHotposition);
            ResultBeanData.ResultBean.HotInfoBean hotInfoBean = datas.get(Hotposition);
            Glide.with(mContext).load(Constants.BASE_IMAGE_URL+hotInfoBean.getFigure()).into(viewHolder.iv_hot);
            viewHolder.bofangliang.setText(hotInfoBean.getBofangliang());
            viewHolder.Id.setText(hotInfoBean.getId());
            viewHolder.tv_title.setText(hotInfoBean.getName());
            viewHolder.tv_red.setText(hotInfoBean.getRed());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return convertView;
    }

    static class ViewHolder {
        ImageView iv_hot;
        TextView bofangliang;
        TextView Id;
        TextView tv_title;
        TextView tv_red;

    }
}
